package com.rd.student.jiaji.class2.shirui.linklist2;

import java.util.LinkedList;

public class Student {
    String name;
    String major;
    int grade;
    String describe;
    int age;

    public Student(String name, String major, int grade, String describe, int age) {
        this.name = name;
        this.major = major;
        this.grade = grade;
        this.describe = describe;
        this.age = age;
    }

    public Student() {

    }


    public String getName() {
        return name;
    }

    public String getMajor() {
        return major;
    }

    public int getGrade() {
        return grade;
    }

    public String getDescribe() {
        return describe;
    }

    public int getAge() {
        return age;
    }


    public static void printAge(LinkedList list, int age) {

        for (Object obj : list) {  // 遍历list 让obj接收
            Student student = (Student) obj; //将obj转换为student 才能调用student中的方法
            if (student.getAge() == age) {
                System.out.println(student);
            }

        }
    }

    public static void printMajor(LinkedList list, String major) {

        for (Object obj : list) {
            Student student = (Student) obj;
            if (student.getMajor() == major) {
                System.out.println(student);
            }
        }
    }

    public static void printAllName(LinkedList list) {
        for (Object obj : list) {
            Student student = (Student) obj;
            System.out.println(student.getName());
        }
    }

    public static void printGrade(LinkedList list, int grade) {

        for (Object obj : list) {
            Student student = (Student) obj;
            if (student.getGrade() == grade) {
                System.out.println(student);
            }
        }
    }

    public static double PingJunAge(LinkedList list) {
        double sum = 0;
        int count = 0;

        for (Object obj : list) {
            Student student = (Student) obj;
            sum = sum + student.getAge(); // 求和
            count++; //记录几个对象

        }
        return sum / count; // 求平均数
    }

    public static void moreAge(LinkedList list, int age) {

        for (Object obj : list) {
            Student student = (Student) obj;
            if (student.age >= age) {
                System.out.println(student);
            }
        }

    }

    public static void lessAge(LinkedList list, int age) {

        for (Object obj : list) {
            Student student = (Student) obj;
            if (student.age <= age) {
                System.out.println(student);
            }
        }

    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", major='" + major + '\'' +
                ", grade=" + grade +
                ", describe='" + describe + '\'' +
                ", age=" + age +
                '}';
    }
}
